home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Utilities / Apple DocViewer™ v1.1.1 / DocViewer Apple Events Info / DocViewer Lookup TechNote / DocViewer Lookup TechNote
Encoding:
Text File  |  1994-09-26  |  17.1 KB  |  35 lines  |  [ONLN/HLX2]

  1. #004 New Apple Event Support in DocViewer 1.1.1
  2.  
  3. Introduction
  4. Beginning with version 1.1.1, Apple DocViewer supports a special Apple event.  This Apple event is known as the "DocViewer Lookup" event.  With this event, it is possible to send a message to DocViewer requesting that it open a particular document and turn to a specific heading.  This DocViewer Tech Note describes the implementation of this event.  Please note that tech notes 1 - 3 do not address the Viewer portion of DocViewer and are only available to licensees of the Apple DocViewer Builder.
  5. DocViewerLookup.h
  6. Accompanying this Tech Note is a C header file for many of the constants and data structures  you will need when interacting programmatically with DocViewer.
  7. Event Parameters
  8. The Lookup event accepts three parameters.  These parameters are encapsulated into a single data structure for this version.  (We will parameterize them at the Apple event level for the next release.)  This data structure is the only parameter of the Apple event.  The structure is defined as:
  9. typedef    struct {
  10.     FSSpec    aDoc;            //    FSSpec for the Doc to open/search
  11.     Str255    aPattern;    //    String in heading to find (length                                 // prefixed)
  12.     short        accessLevel;//    find level 
  13. }SeekParamRec, *SeekParamRecPtr, **SeekParamRecHandle;
  14. The first parameter is an FSSpec to the document you wish to open and perform the lookup in.  DocViewer will open this document if it isn't already open.  This document must be a DocViewer document (Creator: HLX2 Type:ONLN.)  If you pass a document that does not belong to DocViewer, it will return a kWrongFileType in the 'errn' parameter of the Apple event reply.  
  15. The second parameter is the heading you wish DocViewer to look for.  This is a simple Pascal-style string with a maximum length of 255 characters.  DocViewer uses this string as a pattern to match against the document's Table of Contents.  The comparison is accomplished without regard to case or diacritical marks. (e.g. FAT == fAt,  fåt = fat).  If the string you pass in isn't found in the document's Table of Contents, then DocViewer will return a kEntryNotFound error.
  16. The third and final parameter is used to qualify the search pattern in the second parameter.  Once DocViewer has located the entry in the Table of Contents it will confirm that the entry is in the level of the TOC hierarchy specified in the accessLevel field.  DocViewer supports seven levels of hierarchy.  They are defined as follows:
  17. #define        kFirstLevelHier            1
  18. #define        kSecondLevelHier        2
  19. #define        kThirdLevelHier            3
  20. #define        kFourthLevelHier        4
  21. #define        kFigureLevelHier        201
  22. #define        kListLevelHier                202
  23. #define        kTableLevelHier            203
  24. An eighth constant has been defined that will allow the entry to be found at any level in the hierarchy.  In this case, if there are duplicate entries the first entry will be chosen.
  25. #define        kAnyLevelHier                999
  26. Each of these selectors is mutually exclusive, and they cannot be combined (or'd) together.
  27. Sending The Event
  28. Launch DocViewer with Document
  29. The first step when sending the lookup event is to see if DocViewer is currently running.  This can be accomplished with the Process manager GetProcessInfo routine.  If DocViewer is found in the list of currently running processes, you should check to see that the version of DocViewer is correct (1.1.1).  This can be done using the 'vers' resource with ID #1. 
  30. If DocViewer is not running, it is necessary to launch the application with the target document.  If DocViewer is launched without reference to the target document, it will present its default SFGetFile dialog, and you will not be able to message the application until the dialog is dismissed.  For information on launching an application with a document see "LaunchwithDoc" on the latest version of the Developer CD (Tool Chest Edition).
  31. Again, when you launch the application, it is necessary to confirm that you are launching the correct version by checking the contents of the 'vers' ID #1 resource of the DocViewer application.
  32. Send the Event
  33. Once you have determined that DocViewer is running (or you've launched it) you can then send the event.  See listing 1 for an example of sending the 'seek' event.
  34. Check for Errors
  35. If DocViewer cannot find the entry requested, it will return an error in the reply of the Apple event.  See listing 1 for an example of how to determine these errors.
  36. Listing 1 - Sending the 'seek' Apple event
  37. //OpenDoc
  38. // This routine takes a pointer to a SeekParamRec
  39. // and sends it to DocViewer.  This routine assumes
  40. // that you've already checked to see if DocViewer is running
  41. // I removed most the error checking where it was obvious
  42. // to improve readability.
  43. OSErr OpenDoc(SeekParamRec *qData)
  44. {
  45.     OSErr                        err = noErr;
  46.     AppleEvent        myEvent, reply;
  47.     AEDesc                    myAddress;
  48.     long                        appSig = kDocViewerAppSig;
  49.     long                        replyError = noErr;
  50.     Size                        actualSize;
  51.     DescType                gotType;
  52.     
  53.     err = AECreateDesc(    typeApplSignature,(Ptr)&appSig,
  54.                         sizeof(appSig),&myAddress);
  55.     
  56.     err = AECreateAppleEvent(kDocViewerEventClass, kSeekEventID, 
  57.                                                                         &myAddress, kAutoGenerateReturnID, 
  58.                                                                         kAnyTransactionID, &myEvent );
  59.                             
  60.     err = AEPutParamPtr( &myEvent, keySeekParam, typeWildCard,                                                             (Ptr)qData, sizeof(SeekParamRec) );
  61.     err = AESend( &myEvent, &reply, kAEWaitReply,                                                 kAENormalPriority, kAEDefaultTimeout, 
  62.                                         nil, nil );
  63.    // Check to see if you got an error
  64.     err = AEGetParamPtr( &reply, keyErrorNumber, typeLongInteger,                                                             &gotType, (Ptr)&replyError,
  65.                                                           sizeof(long), &actualSize);
  66.     // Special case on AEDescNotFound because we'll get an error
  67.     // if there is no error in the reply.
  68.     if ((err != noErr) && (err != errAEDescNotFound))
  69.     {
  70.         return err;
  71.     }
  72.     // if there's an error from DocViewer return it.
  73.     // otherwise return noErr.
  74.     if (replyError != noErr)
  75.             return replyError;
  76.     else
  77.             return noErr;
  78. }
  79. 2dˇ ˇˇˇˇd°d WORDC«
  80. N~ëE åå@°ñ , Palatino
  81. .C«C«+≤ÉApple DocViewer
  82. †ó°ñ 
  83. (É…Technical Note†ó°ñ 
  84. (LÉ
  85. *' Apple Computer, Inc., Developer Press†óê    häà™¸¸˛ˇ¸ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛?ˇˇ¯ˇ¯ˇ¯ˇ¯ˇ¯ˇ¯¯8ê    häà™¸¸@Ä¿¿«·¿Δ«¿«¡¿ ¿«ÅΔ¿Δ!¿QΔ«…¿%¿‡¿ˇ¸˛ˇ˙˛%įÄ8888ˇ8¯8
  86. d
  87. °dONLNd´~ø(∫~/#004 New Apple Event Support in DocViewer 1.1.1
  88. °dONLNd2·ZÒ©(ÌZ Introduction
  89. °dONLNd?˜~æ+$
  90. Beginning °dONLNdI˜æ
  91. )@6with version 1.1.1, Apple DocViewer supports a special°dONLNdÄ~Ã(~Apple event.  °dONLNdéÃ
  92. )N3This Apple event is known as the "DocViewer Lookup"°dONLNd¬~!Ã(~=event.  With this event, it is possible to send a message to °dONLNdˇÃ!
  93. (à   DocViewer°dONLNd    !~/L(+~%requesting that it open a particular °dONLNd.!L/
  94. )Œdocument and turn to a specific°dONLNdN/~=ˇ(9~@heading.  This DocViewer Tech Note describes the implementation °dONLNdé/ˇ=
  95. (9ˇof°dONLNdë=~Kø(G~
  96. this event.  °dONLNdû=øK
  97. )A;Please note that tech notes 1 - 3 do not address the Viewer°dONLNd⁄K~Y—(U~<portion of DocViewer and are only available to licensees of °dONLNdK—Y
  98. (U—    the Apple°dONLNd Y~gÏ(c~DocViewer Builder.
  99. °dONLNd3uZÖ‹(ÅZDocViewerLookup.h
  100. °dONLNdEã~ôfi+$>Accompanying this Tech Note is a C header file for many of the°dONLNdÑô~ß“*=constants and data structures  you will need when interacting°dONLNd¬ß~µB* programmatically with DocViewer.
  101. °dONLNd„√Z”À(œZEvent Parameters
  102. °dONLNdÙŸ~ÁÓ+$@The Lookup event accepts three parameters.  These parameters are°dONLNd5Á~ıÔ*Eencapsulated into a single data structure for this version.  (We will°dONLNd{ı~*Gparameterize them at the Apple event level for the next release.)  This°dONLNd√~*Gdata structure is the only parameter of the Apple event.  The structure°dONLNd ~≈*is defined as:,
  103. Courier
  104. °dONLNd%~1®*typedef°dONLNd"%¥1‰)6struct {°dONLNd,6¢BΔ(?¢FSSpec°dONLNd36ÿBˆ)6aDoc;°dONLNd;6 B,)H//°dONLNd>62B¯)!FSSpec for the Doc to open/search°dONLNdaG¢SΔ(P¢Str255°dONLNdhGÿS)6    aPattern;°dONLNdrG S,)H//°dONLNduG2S˛)"String in heading to find (length °dONLNdüR ^h([  // prefixed)°dONLNd≠c¢o¿(l¢short°dONLNd¥cÿo,)6accessLevel;//°dONLNd√c2on)Z
  105. find level°dONLNdœt~Ĭ(}~6}SeekParamRec, *SeekParamRecPtr, **SeekParamRecHandle;
  106. °dONLNdÖ~ì
  107. *EThe first parameter is an FSSpec to the document you wish to open and°dONLNdLì~°*Eperform the lookup in.  DocViewer will open this document if it isn't°dONLNdí°~Øÿ*9already open.  This document must be a DocViewer document°dONLNdÃØ~Ω*(Creator: HLX2 Type:ONLN.)°dONLNdʨ∫!(∂ °dONLNdÁØ!ΩÓ+% If you pass a document that does notˇXdˇ ˇˇˇˇd
  108. d, Palatino
  109. .°dONLNdH~VL+~R&belong to DocViewer, it will return a ,
  110. Courier
  111. °dONLNd&ILU¶)ŒkWrongFileType 
  112. °dONLNd5H¶VÍ)Z
  113. in the 'errn'°dONLNdCV~dD(`~#parameter of the Apple event reply.°dONLNdij~x*CThe second parameter is the heading you wish DocViewer to look for.°dONLNdÆx~ÜË*AThis is a simple Pascal-style string with a maximum length of 255°dONLNdÜ~î*Icharacters.  DocViewer uses this string as a pattern to match against the°dONLNd:î~¢„*=document's Table of Contents.  The comparison is accomplished°dONLNdx¢~∞˝*Kwithout regard to case or diacritical marks. (e.g. FAT == fAt,  fåt = fat).°dONLNd≈∞~æÿ*@If the string you pass in isn't found in the document's Table of°dONLNdæ~Ã]*'Contents, then DocViewer will return a 
  114. °dONLNd-ø]À∑)flkEntryNotFound 
  115. °dONLNd<æ∑Ã÷)Zerror.°dONLNdC“~‡˘(‹~FThe third and final parameter is used to qualify the search pattern in°dONLNdä‡~ÓÙ*Bthe second parameter.  Once DocViewer has located the entry in the°dONLNdÕÓ~¸Û*GTable of Contents it will confirm that the entry is in the level of the°dONLNd¸~
  116. )*TOC hierarchy specified in the 
  117. °dONLNd4˝)    k)´ accessLevel
  118. °dONLNd?¸k
  119. )B field.  DocViewer supports°dONLNd[
  120. ~¨(~8seven levels of hierarchy.  They are defined as follows:
  121. °dONLNdî~*®*#define°dONLNdù¥*)6kFirstLevelHier°dONLNdØ2*8)~1°dONLNd±)~5®(2~#define°dONLNd∫)¥5)6kSecondLevelHier°dONLNdÃ)258)~2°dONLNdŒ4~@®(=~#define°dONLNd◊4¥@)6kThirdLevelHier°dONLNdÈ42@8)~3°dONLNdÎ?~K®(H~#define°dONLNdÙ?¥K)6kFourthLevelHier°dONLNd?2K8)~4°dONLNdJ~V®(S~#define°dONLNdJ¥V)6kFigureLevelHier°dONLNd#J2VD)~201°dONLNd'U~a®(^~#define°dONLNd0U¥a)6kListLevelHier°dONLNdBU2aD)~202°dONLNdF`~l®(i~#define°dONLNdO`¥l)6kTableLevelHier°dONLNda`2lD)~203
  122. °dONLNdeq~Ô({~CAn eighth constant has been defined that will allow the entry to be°dONLNd©~ç˝*Jfound at any level in the hierarchy.  In this case, if there are duplicate°dONLNdÙç~õG*'entries the first entry will be chosen.
  123. °dONLNd°~≠®*#define°dONLNd%°¥≠)6
  124. kAnyLevelHier°dONLNd6°2≠D)~999
  125. °dONLNd:≤~¿‡(º~AEach of these selectors is mutually exclusive, and they cannot be°dONLNd|¿~Œ *combined (or'd) together.
  126. °dONLNdñ‹ZÏ—(ËZSending The Event
  127. °dONLNd®Ú~D+$Launch DocViewer with Document°dONLNd«~*FThe first step when sending the lookup event is to see if DocViewer is°dONLNd~"
  128. *Ecurrently running.  This can be accomplished with the Process manager
  129. °dONLNdT#~/“*GetProcessInfo
  130. °dONLNdb"“0˛)T9 routine.  If DocViewer is found in the list of currently°dONLNdú0~>÷(:~>running processes, you should check to see that the version of°dONLNd€>~L*IDocViewer is correct (1.1.1).  This can be done using the 'vers' resource°dONLNd%L~Zº* with ID #1.°dONLNd2`~n˙*FIf DocViewer is not running, it is necessary to launch the application°dONLNdyn~|*Ewith the target document.  If DocViewer is launched without reference°dONLNdø|~ä*Ito the target document, it will present its default SFGetFile dialog, and°dONLNd    ä~ò‰*Cyou will not be able to message the application until the dialog is°dONLNdMò~¶fl*>dismissed.  For information on launching an application with a°dONLNdå¶~¥*Cdocument see "LaunchwithDoc" on the latest version of the Developer°dONLNd–¥~¬*CD (Tool Chest Edition).ˇ
  131. ädˇ ˇˇˇˇd
  132. d, Palatino
  133. .°dONLNdH~V+~RGAgain, when you launch the application, it is necessary to confirm that°dONLNdHV~d˚*Eyou are launching the correct version by checking the contents of the°dONLNdéd~rô*3'vers' ID #1 resource of the DocViewer application.°dONLNd¬x~Ü”*Send the Event°dONLNd—å~öÍ*=Once you have determined that DocViewer is running (or you've°dONLNdö~®*Glaunched it) you can then send the event.  See listing 1 for an example°dONLNdW®~∂*of sending the 'seek' event.°dONLNdtº~ ÿ*Check for Errors°dONLNdÖ–~fi*HIf DocViewer cannot find the entry requested, it will return an error in°dONLNdŒfi~ÏÛ*Ethe reply of the Apple event.  See listing 1 for an example of how to°dONLNdÏ~˙ˇ*determine these errors.
  134.     °dONLNd,ˇ~**Listing 1 - Sending the 'seek' Apple event,
  135. Courier
  136. °dONLNdW ~¥*    //OpenDoc°dONLNda~"§* 1// This routine takes a pointer to a SeekParamRec°dONLNdì!~-∞* 3// and sends it to DocViewer.  This routine assumes°dONLNd«,~8Ï* =// that you've already checked to see if DocViewer is running°dONLNd7~C‘* 9// I removed most the error checking where it was obvious°dONLNd?B~N* // to improve readability.°dONLNdZM~YJ* "OSErr OpenDoc(SeekParamRec *qData)°dONLNd}X~dÑ* {°dONLNdÄcêoÆ+ OSErr°dONLNdãc·o))Q err = noErr;°dONLNdônêzÃ(wê
  137. AppleEvent°dONLNd•n·z;)QmyEvent, reply;°dONLNd∂yêÖ¥(ÇêAEDesc°dONLNd¡y·Ö)Q
  138. myAddress;°dONLNdÕÑêê®(çêlong°dONLNd◊Ñ·ê})QappSig = kDocViewerAppSig;°dONLNdÛèêõ®(òêlong°dONLNd˝è·õS)QreplyError = noErr;°dONLNdöê¶®(£êSize°dONLNdö·¶#)Q actualSize;°dONLNd)•걿(ÆêDescType°dONLNd5•·±)QgotType;°dONLNdAªê«(ƒêerr = AECreateDesc(°dONLNdUª«»)~typeApplSignature,(Ptr)&appSig,°dONLNd{ΔΩ“_(œΩsizeof(appSig),&myAddress);°dONLNdö‹ê˯(Âê<err = AECreateAppleEvent(kDocViewerEventClass, kSeekEventID,°dONLNdÍÁ)Ûı+ô "&myAddress, kAutoGenerateReturnID,°dONLNd Ú)˛›* kAnyTransactionID, &myEvent );°dONLNdHêÚ(ê;err = AEPutParamPtr( &myEvent, keySeekParam, typeWildCard, °dONLNdí‡+~ #(Ptr)qData, sizeof(SeekParamRec) );°dONLNd∑)ê5§(2ê.err = AESend( &myEvent, &reply, kAEWaitReply, °dONLNdÒ4·@ø+Q %kAENormalPriority, kAEDefaultTimeout,°dONLNd"?·K#* nil, nil );°dONLNd.U~ab(^~&   // Check to see if you got an error°dONLNdV`êl+ >err = AEGetParamPtr( &reply, keyErrorNumber, typeLongInteger, °dONLNd£kw∞+~ &gotType, (Ptr)&replyError,°dONLNd≈vΩÇ…(Ω  °dONLNdœvÇ∞)Qsizeof(long), &actualSize);°dONLNdÏÅêç¯(äê<// Special case on AEDescNotFound because we'll get an error°dONLNd*åêòn* %// if there is no error in the reply.°dONLNdQóê£∂* 1if ((err != noErr) && (err != errAEDescNotFound))°dONLNdÑ¢êÆñ* {°dONLNdà≠ôπ€+     return err;°dONLNdï∏êƒñ(¡ê}°dONLNdò√êœ∞* 0// if there's an error from DocViewer return it.ˇRdˇ ˇˇˇˇd
  139. d,
  140. Courier
  141. .°dONLNdHêT,+êQ// otherwise return noErr.°dONLNdSê_ * if (replyError != noErr)°dONLNd8^¢j+ return replyError;°dONLNdLiêu®(rêelse°dONLNdTt¢Ä+
  142. return noErr;°dONLNdb~ãÑ(à~}ˇ